package com.designpattern.creating.origion;

import lombok.Data;

import java.util.HashMap;
import java.util.LinkedHashMap;

/**
 * @Author chengzelee
 * @Date 2022/11/24 17:49
 * @Desc 原型对象，可以写成单例
 */
@Data
public class ObjForOrigin implements Cloneable{

    HashMap hashMap;

    String str;

    public ObjForOrigin() {
        this.hashMap = new LinkedHashMap();
        hashMap.put("map","map");
        this.str = "str";
    }

    /**
     * 深克隆
     */
    @Override
    protected Object clone() throws CloneNotSupportedException {
        ObjForOrigin objForOrigin = (ObjForOrigin) super.clone();
        objForOrigin.hashMap = (HashMap) hashMap.clone();
        return objForOrigin;
    }
}
